<?
    include "../../php/common.php";
    $pname = $_POST['pname'];
    $price = $_POST['price'];
    $type = $_POST['type'];

    if(!file_exists("uploads")){     //看是否存在文件夹uploads
        mkdir("uploads");
    }

    $path = $_FILES['img']['tmp_name'];

    move_uploaded_file($path,"uploads/".$_FILES['img']['name']);
    $imgSrc = $_FILES['img']['name'];

    $sql = "INSERT INTO product (pname,price,`type`,srcImg) VALUES ('{$pname}',{$price},{$type},'{$imgSrc}')";

    // echo $sql ; 
    $arr = [] ;
    $res = mysqli_query($link,$sql);
    if( $res ){
        $arr['status'] = 1;
        $arr['info'] = "添加成功";
    } else{
        $arr['status'] = 0;
        $arr['info'] = "添加失败";
    }
    echo json_encode($arr);
?>